<!DOCTYPE HTML>
<html lang="zh_CN" class="sidebar-visible no-js light">
    <head>
        <!-- Book generated using mdBook -->
        <meta charset="UTF-8">
        <title>从单引擎迁移 - Lithium 双引擎 v0.0.1</title>
        <!-- Custom HTML head -->
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="theme-color" content="#ffffff" />

        <link rel="icon" href="favicon.svg">
        <link rel="shortcut icon" href="favicon.png">
        <link rel="stylesheet" href="css/variables.css">
        <link rel="stylesheet" href="css/general.css">
        <link rel="stylesheet" href="css/chrome.css">
        <link rel="stylesheet" href="css/print.css" media="print">
        <!-- Fonts -->
        <link rel="stylesheet" href="FontAwesome/css/font-awesome.css">
        <link rel="stylesheet" href="fonts/fonts.css">
        <!-- Highlight.js Stylesheets -->
        <link rel="stylesheet" href="highlight.css">
        <link rel="stylesheet" href="tomorrow-night.css">
        <link rel="stylesheet" href="ayu-highlight.css">

        <!-- Custom theme stylesheets -->
    </head>
    <body>
        <!-- Provide site root to javascript -->
        <script type="text/javascript">
            var path_to_root = "";
            var default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "navy" : "light";
        </script>

        <!-- Work around some values being stored in localStorage wrapped in quotes -->
        <script type="text/javascript">
            try {
                var theme = localStorage.getItem('mdbook-theme');
                var sidebar = localStorage.getItem('mdbook-sidebar');

                if (theme.startsWith('"') && theme.endsWith('"')) {
                    localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
                }

                if (sidebar.startsWith('"') && sidebar.endsWith('"')) {
                    localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
                }
            } catch (e) { }
        </script>

        <!-- Set the theme before any content is loaded, prevents flash -->
        <script type="text/javascript">
            var theme;
            try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
            if (theme === null || theme === undefined) { theme = default_theme; }
            var html = document.querySelector('html');
            html.classList.remove('no-js')
            html.classList.remove('light')
            html.classList.add(theme);
            html.classList.add('js');
        </script>

        <!-- Hide / unhide sidebar before it is displayed -->
        <script type="text/javascript">
            var html = document.querySelector('html');
            var sidebar = 'hidden';
            if (document.body.clientWidth >= 1080) {
                try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
                sidebar = sidebar || 'visible';
            }
            html.classList.remove('sidebar-visible');
            html.classList.add("sidebar-" + sidebar);
        </script>

        <nav id="sidebar" class="sidebar" aria-label="Table of contents">
            <div class="sidebar-scrollbox">
                <ol class="chapter"><li class="chapter-item expanded "><a href="intro.html"><strong aria-hidden="true">1.</strong> 简介</a></li><li class="chapter-item expanded "><a href="Upgrade.html" class="active"><strong aria-hidden="true">2.</strong> 从单引擎迁移</a></li><li class="chapter-item expanded "><a href="basic.html"><strong aria-hidden="true">3.</strong> 基本用法</a></li><li class="chapter-item expanded "><a href="web/web.html"><strong aria-hidden="true">4.</strong> 网页接口</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="web/dev-tools.html"><strong aria-hidden="true">4.1.</strong> 开发者工具</a></li><li class="chapter-item expanded "><a href="web/env.html"><strong aria-hidden="true">4.2.</strong> env</a></li><li class="chapter-item expanded "><a href="web/exit.html"><strong aria-hidden="true">4.3.</strong> exit</a></li><li class="chapter-item expanded "><a href="web/main-window.html"><strong aria-hidden="true">4.4.</strong> MainWindow 类</a></li><li class="chapter-item expanded "><a href="web/open-window.html"><strong aria-hidden="true">4.5.</strong> 打开窗口</a></li><li class="chapter-item expanded "><a href="web/plugins.html"><strong aria-hidden="true">4.6.</strong> 插件</a></li><li class="chapter-item expanded "><a href="web/struct-type.html"><strong aria-hidden="true">4.7.</strong> ctype</a></li><li class="chapter-item expanded "><a href="web/shell.html"><strong aria-hidden="true">4.8.</strong> 运行本地脚本</a></li><li class="chapter-item expanded "><a href="web/tray-icon.html"><strong aria-hidden="true">4.9.</strong> 系统托盘</a></li></ol></li><li class="chapter-item expanded "><a href="cmdline.html"><strong aria-hidden="true">5.</strong> 命令行参数</a></li><li class="chapter-item expanded "><a href="runtime.html"><strong aria-hidden="true">6.</strong> 运行时</a></li><li class="chapter-item expanded "><a href="crash-report.html"><strong aria-hidden="true">7.</strong> 崩溃报告</a></li><li class="chapter-item expanded "><a href="transparent-window.html"><strong aria-hidden="true">8.</strong> 透明窗口</a></li><li class="chapter-item expanded "><a href="preferences.html"><strong aria-hidden="true">9.</strong> Preferences 配置文件</a></li></ol>
            </div>
            <div id="sidebar-resize-handle" class="sidebar-resize-handle"></div>
        </nav>

        <div id="page-wrapper" class="page-wrapper">

            <div class="page">
                <div id="menu-bar-hover-placeholder"></div>
                <div id="menu-bar" class="menu-bar sticky bordered">
                    <div class="left-buttons">
                        <button id="sidebar-toggle" class="icon-button" type="button" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
                            <i class="fa fa-bars"></i>
                        </button>
                        <button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
                            <i class="fa fa-paint-brush"></i>
                        </button>
                        <ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
                            <li role="none"><button role="menuitem" class="theme" id="light">Light (default)</button></li>
                            <li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li>
                            <li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li>
                            <li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
                            <li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
                        </ul>
                        <button id="search-toggle" class="icon-button" type="button" title="Search. (Shortkey: s)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="S" aria-controls="searchbar">
                            <i class="fa fa-search"></i>
                        </button>
                    </div>

                    <h1 class="menu-title">Lithium 双引擎 v0.0.1</h1>

                    <div class="right-buttons">
                        <a href="print.html" title="Print this book" aria-label="Print this book">
                            <i id="print-button" class="fa fa-print"></i>
                        </a>
                    </div>
                </div>

                <div id="search-wrapper" class="hidden">
                    <form id="searchbar-outer" class="searchbar-outer">
                        <input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
                    </form>
                    <div id="searchresults-outer" class="searchresults-outer hidden">
                        <div id="searchresults-header" class="searchresults-header"></div>
                        <ul id="searchresults">
                        </ul>
                    </div>
                </div>
                <!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
                <script type="text/javascript">
                    document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
                    document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
                    Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
                        link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
                    });
                </script>

                <div id="content" class="content">
                    <main>
                        <h1 id="浏览器迁移过程"><a class="header" href="#浏览器迁移过程">浏览器迁移过程</a></h1>
<blockquote>
<p>新旧引擎使用差异。本篇对已经有使用单引擎的用户提供。</p>
</blockquote>
<p>尽管我们秉承着 &quot;不让已有用户修改代码&quot; 的原则，但是由于技术架构的现实原因导致不可避免的部分代码修改。我们已经最大限度的做了使用方式上的兼容。</p>
<ul>
<li>标记为 兼容 的，原则上不需要修改适配。此处提出是为了在时间资源充裕时推荐更规范的使用方式。</li>
</ul>
<h2 id="1兼容驼峰命名"><a class="header" href="#1兼容驼峰命名">1.[兼容]驼峰命名</a></h2>
<p>目前已经尽可能兼容了旧参数，原则上不需要修改(但是新开发的项目打算使用双引擎时仍然建议使用更规范的命名方式)</p>
<pre><code>keep_above=&gt;keepAbove,skip_bar=&gt;skipBar,begin_move=&gt;beginMove
</code></pre>
<h2 id="2兼容命令行参数"><a class="header" href="#2兼容命令行参数">2.[兼容]命令行参数</a></h2>
<p>原先使用一个横杠传递参数的，新引擎应使用两个横杠</p>
<blockquote>
<p>配置 LITHIUM_ENABLE_XPC_URLS 时，双引擎需要<code>;</code>分隔的单项至少是一个完整的域名，端口号是域名的一部分。</p>
</blockquote>
<h2 id="3小变动-自定义资源文件目录"><a class="header" href="#3小变动-自定义资源文件目录">3.[小变动] 自定义资源文件目录</a></h2>
<p>原先单引擎自定义的资源文件使用习惯不变，目录改为 ./gecko/</p>
<h2 id="4小变动-任务栏右键关闭事件绑定"><a class="header" href="#4小变动-任务栏右键关闭事件绑定">4.[小变动] 任务栏右键关闭事件绑定</a></h2>
<p>给原先绑定事件 由用户控制是否 <code>e.preventDefault();</code> 而双引擎中用户只需要返回 bool 值。</p>
<p>您还可以通过查看 手册 中的 <code>main-window</code> 一节 <code>onclose</code>  查看使用示例。</p>
<h2 id="5小变动背景透明设置"><a class="header" href="#5小变动背景透明设置">5.[小变动]背景透明设置</a></h2>
<p>单引擎版本背景色和透明选项可以一个参数设置好，双引擎版本必须使用两个参数来达到目的。</p>
<p>最终逻辑是，使用两个参数来达到控制背景色的目的，虽然Gecko会忽略是否透明的选项(仅根据背景色的透明值即可判断)</p>
<pre><code class="language-shell">--background-color='#fff'
--background-transparent
</code></pre>
<h2 id="6兼容lnksmainwindowwindow"><a class="header" href="#6兼容lnksmainwindowwindow">6.[兼容]lnks.MainWindow(window)</a></h2>
<p>在双引擎的Chrome中会忽略 window 参数。只能创建当前窗口的实例。 这本身不用调整什么，虽然不用传递该参数，但还是做了兼容允许传递该参数（代码不用改）。 需要注意的是，所有此前通过 返回得到 lnks.MainWindow(
window) 实例并加以控制窗口行为的都建议通过获取所有窗口实例的思路进行。</p>
<h2 id="7基本兼容托盘"><a class="header" href="#7基本兼容托盘">7.[基本兼容]托盘</a></h2>
<p><code>this.trayIcon = new lnks.TrayIcon(window, iconUrl);</code> 在双引擎的Chrome中会忽略 window 参数。 另外，支持了 <code>iconUrl</code>
参数可选，当不传递此参数时，将使用 <code>gecko/default.ico</code> 做为托盘图标。</p>
<p>事件绑定建议在托盘创建页面完成。代码完全兼容，只是以前建议由托盘菜单页面负责事件绑定，改为由创建页面负责事件绑定。</p>
<h2 id="8继续控制打开的子窗口子应用"><a class="header" href="#8继续控制打开的子窗口子应用">8.继续控制打开的子窗口(子应用)</a></h2>
<p>单引擎版本通过保存返回的窗口实例对象来继续操作窗口，双引擎无法使用相同方法。 双引擎推荐通过遍历所有窗口后得到指定窗口实例再加以控制的方法。 当前(2021.12.9)我们仍在努力兼容单引擎版本的返回窗口实例功能，使尽可能兼容。</p>
<h2 id="9新开窗口openwindow2"><a class="header" href="#9新开窗口openwindow2">9.新开窗口(openWindow2)</a></h2>
<p><code>lnks.openWindow2(win_args,user_args)</code></p>
<p>由于双引擎的技术局限性，在传递user_args时，只能传递可序列化后完整反序列化的对象（普通字段属性key=&gt;val的对象依然可用，不可以将一个 new
Window的窗口实例在此处传递，比如托盘实例，因为双引擎通信无法满足这个对象的目的，运行环境完全变了）。</p>

                    </main>

                    <nav class="nav-wrapper" aria-label="Page navigation">
                        <!-- Mobile navigation buttons -->
                            <a rel="prev" href="intro.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
                                <i class="fa fa-angle-left"></i>
                            </a>
                            <a rel="next" href="basic.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
                                <i class="fa fa-angle-right"></i>
                            </a>
                        <div style="clear: both"></div>
                    </nav>
                </div>
            </div>

            <nav class="nav-wide-wrapper" aria-label="Page navigation">
                    <a rel="prev" href="intro.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
                        <i class="fa fa-angle-left"></i>
                    </a>
                    <a rel="next" href="basic.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
                        <i class="fa fa-angle-right"></i>
                    </a>
            </nav>

        </div>

        <script type="text/javascript">
            window.playground_copyable = true;
        </script>
        <script src="elasticlunr.min.js" type="text/javascript" charset="utf-8"></script>
        <script src="mark.min.js" type="text/javascript" charset="utf-8"></script>
        <script src="searcher.js" type="text/javascript" charset="utf-8"></script>
        <script src="clipboard.min.js" type="text/javascript" charset="utf-8"></script>
        <script src="highlight.js" type="text/javascript" charset="utf-8"></script>
        <script src="book.js" type="text/javascript" charset="utf-8"></script>

        <!-- Custom JS scripts -->
    </body>
</html>
